﻿using UnityEngine;

namespace Game
{
    public class SceneObjectActionComponent : IComponent
    {
        private Animator _animator;
        private int _cacheTriggerId = 0;

        public SceneObjectActionComponent()
        {
        }
        
        public void Dispose()
        {
        }

        public void Setup(Animator animator)
        {
            _animator = animator;
            if (_cacheTriggerId != 0)
            {
                SetTrigger(_cacheTriggerId);
            }
        }

        public void SetTrigger(int triggerId)
        {
            if (_cacheTriggerId != 0)
            {
                if (_animator != null)
                {
                    _animator.ResetTrigger(_cacheTriggerId);
                }
            }
            _cacheTriggerId = triggerId;
            if (_animator != null)
            {
                _animator.SetTrigger(_cacheTriggerId);
            }
        }
    }
}